//
//  LY_HandlerTool.m
//  recordTest
//
//  Created by Jason on 2017/6/1.
//  Copyright © 2017年 LiuYu. All rights reserved.
//

#import "LY_HandlerTool.h"

@implementation LY_HandlerTool

- (instancetype)init
{
    self = [super init];
    if (self) {
        _orderHandle = 0;
    }
    return self;
}

- (LY_ORDER_TYPE)Recognize:(NSString *)orderStr{
    if (_orderHandle > orderStr.length) {
        _orderHandle = 0;
    }
    NSString *tmpOrder = [orderStr substringFromIndex:_orderHandle];// 最新指令
    NSRange range = [tmpOrder rangeOfString:@"开灯"];
    if (range.location != NSNotFound) {
        _orderHandle += tmpOrder.length;
        return LY_ORDER_TYPE_OnLight;
    }
    
    NSRange range1 = [tmpOrder rangeOfString:@"拍照"];
    if (range1.location != NSNotFound) {
        _orderHandle += tmpOrder.length;
        return LY_ORDER_TYPE_TAKEPHOTO;
    }
    
    NSRange range2 = [tmpOrder rangeOfString:@"关灯"];
    if (range2.location != NSNotFound) {
        _orderHandle += tmpOrder.length;
        return LY_ORDER_TYPE_DownLight;
    }
    
    NSRange range3 = [tmpOrder rangeOfString:@"启动"];
    if (range3.location != NSNotFound) {
        _orderHandle += tmpOrder.length;
        return LY_ORDER_TYPE_STARTCAMERA;
    }
    
    NSRange range4 = [tmpOrder rangeOfString:@"返回"];
    if (range4.location != NSNotFound) {
        _orderHandle += tmpOrder.length;
        return LY_ORDER_TYPE_BACK;
    }
    return LY_ORDER_TYPE_NULL;
}
@end
